﻿using MediatR;
using Traceability.APP.Applications.Commands.YangZhi;
using Traceability.APP.Dtos;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.APP.Applications.CommandHandlers.YangZhi
{
    public class YangZhiXIangqingCommandHandler : IRequestHandler<YangZhiXIangqingCommand, APIResult<FarmModel>>
    {
        private readonly IBaseRepository<FarmModel> _farmRepository;

        public YangZhiXIangqingCommandHandler(IBaseRepository<FarmModel> farmRepository)
        {
            _farmRepository = farmRepository;
        }

        public Task<APIResult<FarmModel>> Handle(YangZhiXIangqingCommand request, CancellationToken cancellationToken)
        {
            APIResult<FarmModel> result = new APIResult<FarmModel>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _farmRepository.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
